<template>
  <div class="legend-box">
    <div
      class="legend-items"
      v-for="(value, index) in object"
      :key="index"
      @click="setLayerVisible(value.layerId)"
    >
      <span class="legend-item"></span>
      <span>{{ value.name }}</span>
      <span>{{ index }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'legendLayer',
  data() {
    return {
      key: '',
      object: [
        {
          name: 'aa',
          layerId: 'polygon2020',
        },
        {
          name: 'bb',
          layerId: 'testpolyline',
        },
        {
          name: 'cc',
          layerId: 'test',
        },
      ],
    }
  },
  methods: {
    setLayerVisible(id) {
      //发送消息
      this.$bus.$emit('gggg-click', id)
    },
  },
}
</script>

<style>
.legend-box {
  position: absolute;
  top: 200px;
  left: 100px;
}
.legend-item {
  background-color: tomato;
  height: 20px;
  width: 45px;
}
.legend-items {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 5px 0;
  cursor: pointer;
}
</style>
